﻿using System;
using TechTalk.SpecFlow;
using Agility.TestProject.AppDriver;
using NUnit.Framework;
using Agility.TestProject.WebAii;
using System.Linq;

namespace Agility.Testing.Web.Features.StepDefinitions
{
    [Binding]
    public class ManageEpicsSteps
    {

        #region Givens
        [Given(@"I have started a Browser")]
        public void GivenIHaveStartedABrowser()
        {
            ((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).StartBrowser();
        }

        [Given(@"there are ideas available in the data store which I submitted")]
        public void GivenThereAreIdeasAvailableInTheDataStoreWhichISubmitted()
        {
            ((AppDriverBase)ScenarioContext.Current["AppDriver"]).CreateEpicsForMyIdeas();
        }

        [Given(@"I am logged in as ""(.*)""")]
        public void GivenIAmLoggedInAs(string p0)
        {
            if (FeatureContext.Current.FeatureInfo.Tags.Contains("SilverLight"))
            {
                ((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).EnsureRoleAssignmentAndLogin(p0); 
            }
        }

        [Given(@"I have navigated to the Home page")]
        public void GivenIHaveNavigatedToTheHomePage()
        {
        }

        [Given(@"there are epics available in the data store")]
        public void GivenThereAreEpicsAvailableInTheDataStore()
        {
            ScenarioContext.Current.Pending();
        }

        [Given(@"the are not approved epics available in the data store")]
        public void GivenTheAreNotApprovedEpicsAvailableInTheDataStore()
        {
            ScenarioContext.Current.Pending();
        }

        #endregion

        #region Whens

        [When(@"I have chosen to add a new idea")]
        public void WhenIHaveChosenToAddANewIdea()
        {
            if (FeatureContext.Current.FeatureInfo.Tags.Contains("SilverLight"))
            {
                ((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).AddNewIdea();
            }
            if (FeatureContext.Current.FeatureInfo.Tags.Contains("MSExcel"))
            {
                ((AgilityExcelDriver)ScenarioContext.Current["AppDriver"]).AddNewIdea();
            }
        }

        [When(@"I have entered a Titel and Description")]
        public void WhenIHaveEnteredATitelAndDescription()
        {
            if (FeatureContext.Current.FeatureInfo.Tags.Contains("SilverLight"))
            {
                ((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).EnterIdeaDetails();
            }
            if (FeatureContext.Current.FeatureInfo.Tags.Contains("MSExcel"))
            {
                ((AgilityExcelDriver)ScenarioContext.Current["AppDriver"]).EnterIdeaDetails();
            }
        }

        [When(@"I have confirmed my input")]
        public void WhenIHaveConfirmedMyInput()
        {
            ((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).ConfirmIdea();
        }

        [When(@"I have selected an idea from the list")]
        public void WhenIHaveSelectedAnIdeaFromTheList()
        {
            ((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).SelectIdeaFromGrid();
        }

        [When(@"I have changed the Titel and Description")]
        public void WhenIHaveChangedTheTitelAndDescription()
        {
            ((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).UpdateIdeaDetails();
            ((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).EnterIdeaDetails();
        }

        [When(@"I press Get Ideas")]
        public void WhenIPressGetIdeas()
        {
            ((AgilityExcelDriver)ScenarioContext.Current["AppDriver"]).GetMyIdeas();
        }

        [When(@"I press Publish Changes")]
        public void WhenIPressPublishChanges()
        {
            ScenarioContext.Current.Pending();
            ((AgilityExcelDriver)ScenarioContext.Current["AppDriver"]).PublishChanges();
        }

        [When(@"I have navigated to the New Ideas page")]
        public void WhenIHaveNavigatedToTheNewIdeasPage()
        {
            ScenarioContext.Current.Pending();
        }

        [When(@"I have navigated to the Approve New Ideas page")]
        public void WhenIHaveNavigatedToTheApproveNewIdeasPage()
        {
            ScenarioContext.Current.Pending();
        }

        #endregion

        #region Thens

        [Then(@"the system displays all my ideas in a list sorted by date of submission and then title")]
        public void ThenTheSystemDisplaysAllMyIdeasInAListSortedByDateOfSubmissionAndThenTitle()
        {
            if (FeatureContext.Current.FeatureInfo.Tags.Contains("SilverLight"))
            {
                Assert.That(((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).VerifyAllMyIdeasDisplayed(), Is.True);
            }
            if (FeatureContext.Current.FeatureInfo.Tags.Contains("MSExcel"))
            {
                Assert.That(((AgilityExcelDriver)ScenarioContext.Current["AppDriver"]).VerifyAllMyIdeasDisplayed(), Is.True);
            }
        }

        [Then(@"shows the title, description, date of submission and approval status for each idea")]
        public void ThenShowsTheTitleDescriptionDateOfSubmissionAndApprovalStatusForEachIdea()
        {
            if (FeatureContext.Current.FeatureInfo.Tags.Contains("SilverLight"))
            {
                Assert.That(((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).VerifyAllMyIdeasDetailsDisplayed(), Is.True);
            }
            if (FeatureContext.Current.FeatureInfo.Tags.Contains("MSExcel"))
            {
                Assert.That(((AgilityExcelDriver)ScenarioContext.Current["AppDriver"]).VerifyAllMyIdeasDetailsDisplayed(), Is.True);
            }
        }

        [Then(@"the ID column is read only")]
        public void ThenTheIDColumnIsReadOnly()
        {
            Assert.That(((AgilityExcelDriver)ScenarioContext.Current["AppDriver"]).VerifyColumnIsReadOnly("Id"), Is.True);
        }

        [Then(@"the system adds the idea to the list of My Ideas")]
        public void ThenTheSystemAddsTheIdeaToTheListOfMyIdeas()
        {
            ((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).VerifyAllMyIdeasDisplayed();
        }

        [Then(@"the system displays my changes in the list")]
        public void ThenTheSystemDisplaysMyChangesInTheList()
        {
            Assert.IsTrue(((AgilitySilverLightDriver)ScenarioContext.Current["AppDriver"]).VerifyUpdatedDetailsDisplayed());
        }

        [Then(@"the system displays all ideas where the assessment is not yet approved in a list")]
        public void ThenTheSystemDisplaysAllIdeasWhereTheAssessmentIsNotYetApprovedInAList()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"shows all information about each idea \(title, description, date of submission, requester\)")]
        public void ThenShowsAllInformationAboutEachIdeaTitleDescriptionDateOfSubmissionRequester()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"shows all information about each assessment \(effort sizing, potential business value rating, strategy alignment factor, ranking value\)")]
        public void ThenShowsAllInformationAboutEachAssessmentEffortSizingPotentialBusinessValueRatingStrategyAlignmentFactorRankingValue()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"sorts the list by ranking value and then submission date")]
        public void ThenSortsTheListByRankingValueAndThenSubmissionDate()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"shows not assessed epics at the top of the list")]
        public void ThenShowsNotAssessedEpicsAtTheTopOfTheList()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"the system displays all assessed but not yet approved ideas")]
        public void ThenTheSystemDisplaysAllAssessedButNotYetApprovedIdeas()
        {
            ScenarioContext.Current.Pending();
        }
        #endregion
    }
}
